﻿<?php
include_once("./function.php");
$sql="select * from ts_order";
$res=mysqli_query($link,$sql);
if(is_object($res))
{
	$total=mysqli_num_rows($res);
	$num=8;
	$pages=ceil($total/$num);
	$page=1;
	if(isset($_GET['page']))
	{
		$page=$_GET['page'];
	}
	$start=($page-1)*$num;
}
$sql="select * from ts_order limit $start,$num";
$res=mysqli_query($link,$sql);
if(is_object($res))
{
	if((mysqli_num_rows($res))>0)
	{
		$ts_o=array();
		while(($list=mysqli_fetch_assoc($res))!=false)
		{
			$ts_o[]=$list;
		}
	}
}	
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>主体部分</title>
<base target="_self">
<link rel="stylesheet" type="text/css" href="skin/css/base.css" />
<link rel="stylesheet" type="text/css" href="skin/css/main.css" />
</head>
<body leftmargin="8" topmargin='8'>
<form action="product.php" method="get" align="center">
<?php include_once("./function.php");?>
<table width="98%" align="center" border="0" cellpadding="3" cellspacing="1" bgcolor="#CBD8AC" style="margin-bottom:8px;margin-top:8px;">
  <tr>
    <td background="./skin/images/frame/wbg.gif" bgcolor="#EEF4EA" class='title' border="0px"><span><img src='./skin/images/frame/arr3.gif' style='margin-right:10px;'>订单管理</span></td>
	<td align="right" background="./skin/images/frame/wbg.gif" bgcolor="#EEF4EA" class='title' border="0px"></td>
  </tr>
  <tr bgcolor="#FFFFFF">
    <td colspan="2">
		<table width="98%" border="0" cellpadding="2" cellspacing="1" bgcolor="#CFCFCF" align="center" style="margin-top:8px">
		
			<tr align="center" bgcolor="#FBFCE2" height="25">
				<td width="6%">ID</td>
				<td>订单号</td>
				<td width="20%">下单时间</td>
				<td width="15%">付款状态</td>
				<td width="15%">发货状态</td>
				<td width="15%">收货人</td>
				<td width="15%">购买者</td>
				<td>操作</td>
			</tr>
  <!-- data start-->
		<?php
			if(isset($ts_o)){
				foreach($ts_o as $v){
				$sql="select * from ts_address where addr_id=$v[addr_id]";
				$res=mysqli_query($link,$sql);
				if(is_object($res))
				{
					if(mysqli_num_rows($res)==1)
					{
						$one=mysqli_fetch_assoc($res);
						$consignee=$one['consignee'];
						$uid=$one['u_id'];
					}
				}
				if(isset($uid))
			{
				$sql="select * from ts_user where uid='$uid'";
				//echo $sql;
				$res=mysqli_query($link,$sql);
				if(is_object($res))
				{
					if(mysqli_num_rows($res)==1)
					{
						$one1=mysqli_fetch_assoc($res);
						$username=$one1['username'];
					}
				}
			}
		?>
			<tr align='center' bgcolor="#FFFFFF" height="26" align="center" onMouseMove="javascript:this.bgColor='#FCFDEE';" onMouseOut="javascript:this.bgColor='#FFFFFF';">
				<td nowrap><?=$v['order_id']?></td>
				<td><?=$v['order_sn']?></td>
				<td><?=date("Y-m-d H:i:s",$v['order_time'])?></td>

				<td>
				<?php if($v['pay_status']==0){?>
					<font color="red" size="4">未付款</font>
					<?php }elseif($v['pay_status']==1){?><font color="green">已付款</font>
					<?php }?>
					
				</td>

				<td>
				<?php if($v['pay_status']==1){if($v['delivery_status']==0){?>
					<font color="red" size="4">未发货
						<font color="blue" size="4">
							<a href="do_fahuo.php?order_id=<?=$v['order_id']?>">去发货</a>
						</font>
					</font>
					<?php }elseif($v['delivery_status']==1){?>
					<font color="green">已发货</font>
					<?php }elseif($v['delivery_status']==2){?>
					<font color="green" size="4">已收货</font>
					<?php }} else{?>
					<font color="red" size="4">未发货</font>
					<?php }?>
				</td>


				<td><?=isset($consignee)?$consignee:"" ?></td>
				<td><?=isset($username)?$username:"" ?></td>
				<td>
					<a href="./order_detail.php?oid=<?=$v['order_id']?>&user_id=<?=$v['user_id']?>"><img src='./skin/images/frame/trun.gif' title="编辑" alt="编辑" onClick="QuickEdit(179, event, this);" style='cursor:pointer' border='0' width='16' height='16' />
					</a>	
				</td>
			</tr>
			<?php }}?>
				</table>
			</td>
		  </tr>
  <!-- data end-->

  <!-- page start-->
	  <tr align="right" bgcolor="#F9FCEF">
		<td colspan=8 align="center">
			<?php if(isset($page)&&$page>1){?>
				<a href="order.php?page=<?=$page-1?>">上一页</a>
			<?php }?>

			第<?=isset($page)?$page:1?>页/共<?=isset($pages)?$pages:1?>页

			<?php if(isset($page)&&$page<$pages){?>
				<a href="order.php?page=<?=$page+1?>">下一页</a>
			<?php }?>
		</td>
	  </tr>
  <!-- page end-->
  
</table>
</form>

</body>
</html>
